package com.immunology.database.transformers;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.immunology.core.BaseTransformer;
import com.immunology.database.DbColumns;
import com.immunology.model.Patient;
import com.immunology.model.enums.Gender;

public class PatientTransformer extends BaseTransformer<Patient>{
	private static final Logger LOG = Logger
			.getLogger(PatientTransformer.class);

	@Override
	public Patient transformTo(ResultSet resultSet) {
		Patient patient = new Patient();
		try {
			patient.setId(resultSet.getInt(DbColumns.FIRST_COLUMN));
			patient.setFirstName(resultSet.getString(DbColumns.SECOND_COLUMN));
			patient.setMiddleName(resultSet.getString(DbColumns.THIRD_COLUMN));
			patient.setLastName(resultSet.getString(DbColumns.FOURTH_COLUMN));
			patient.setGender(Gender.fromValue(resultSet.getString(DbColumns.FIFTH_COLUMN)));
			patient.setBirthday(resultSet.getDate(DbColumns.SIXTH_COLUMN));
			patient.setCountry(resultSet.getString(DbColumns.SEVENTH_COLUMN));
			patient.setRegion(resultSet.getString(DbColumns.EIGHTH_COLUMN));
			patient.setDistrict(resultSet.getString(DbColumns.NINTH_COLUMN));
			patient.setCity(resultSet.getString(DbColumns.TENTH_COLUMN));
			patient.setStreet(resultSet.getString(DbColumns.ELEVENTH_COLUMN));
			patient.setHouse(resultSet.getString(DbColumns.TWELFTH_COLUMN));
			patient.setFlat(resultSet.getString(DbColumns.THIRTEENTH_COLUMN));

		} catch (SQLException e) {
			LOG.error("Can't create PatientTransformer object:", e);
		}
		return patient;
	}
}
